//
//  DetailsCourseViewController.m
//  WheatPlan
//
//  Created by 王晨辉 on 15/7/13.
//  Copyright (c) 2015年 IOSTeam. All rights reserved.
//

#import "DetailsCourseViewController.h"
#import "RegistrationViewController.h"
@interface DetailsCourseViewController (){
    
    int a;
}

@end

@implementation DetailsCourseViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    //设置导航栏头文字
    self.navigationItem.title = @"课程详情";
    //设置导航栏背景颜色
    [self.navigationController.navigationBar setBarTintColor:[GetFileModel colorWithHexString:@"#ef5858" alpha:1]];
    //设置导航栏字体颜色
    [self.navigationController.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor],NSForegroundColorAttributeName,nil]];    //左边按钮
    
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    [button setBackgroundImage:[UIImage imageNamed:@"_0000_返回.png"]
                      forState:UIControlStateNormal];
    [button addTarget:self action:@selector(back)
     forControlEvents:UIControlEventTouchUpInside];
    button.frame = CGRectMake(0, 0, 20, 15);
    
    a = 1;
    
    UIBarButtonItem *menuButton = [[UIBarButtonItem alloc] initWithCustomView:button];
    
    self.navigationItem.leftBarButtonItem = menuButton;
    self.view.backgroundColor = [UIColor whiteColor];
    [self subView];
    
    
    // Do any additional setup after loading the view.
}
-(void)back{
    
    [self dismissViewControllerAnimated:YES completion:nil];
    
}
-(void)subView{
    
    
    
    UILabel * longLab = [[UILabel alloc]initWithFrame:CGRectMake(0, NavbarHight+15, SCREEN_WIDTH, 30)];
    longLab.text = @"课程";
    longLab.font = [UIFont systemFontOfSize:22];
    longLab.textAlignment = NSTextAlignmentCenter;
    [self.view addSubview:longLab];
    
    

    UIButton * payBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    payBtn.frame = CGRectMake(-10, SCREEN_HEIGHT-50, SCREEN_WIDTH+20, 50);
    [payBtn setBackgroundImage:[UIImage imageNamed:@"确认支付-点击后@2x.png"] forState:UIControlStateNormal];
    [payBtn addTarget:self action:@selector(chooseBoy) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:payBtn];
    
    
    
    UIView * view1 = [[UIView alloc]initWithFrame:CGRectMake(0, SCREEN_HEIGHT-99, SCREEN_WIDTH, 1)];
    view1.backgroundColor = UIColorWithRGBA(229, 229, 231, 1);
    [self.view addSubview:view1];
    
    mayLab = [[UILabel alloc]initWithFrame:CGRectMake(SCREEN_WIDTH-130, SCREEN_HEIGHT-100, 60, 50)];
    mayLab.text =@"需支付:";
    mayLab.font = [UIFont systemFontOfSize:17];
    mayLab.textAlignment = NSTextAlignmentLeft;
    mayLab.textAlignment = NSTextAlignmentLeft;
    [self.view addSubview:mayLab];
    
    numberLab = [[UILabel alloc]initWithFrame:CGRectMake(SCREEN_WIDTH-70, SCREEN_HEIGHT-100, 70, 50)];
    numberLab.text =self.number;
    numberLab.textColor = [UIColor orangeColor];
    numberLab.font = [UIFont systemFontOfSize:22];
    numberLab.adjustsFontSizeToFitWidth = YES;
    numberLab.textAlignment = NSTextAlignmentLeft;
    [self.view addSubview:numberLab];
    
    
    PlusBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    PlusBtn.frame = CGRectMake(10+20+10+50+10, SCREEN_HEIGHT-100+15, 20, 20);
    [PlusBtn setBackgroundImage:[UIImage imageNamed:@"Plus.png"] forState:UIControlStateNormal];
    [PlusBtn addTarget:self action:@selector(PlusAndReduction:) forControlEvents:UIControlEventTouchUpInside];
    PlusBtn.tag = 100;
    [self.view addSubview:PlusBtn];
    
    
    SmallBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    SmallBtn.frame = CGRectMake(10+20+10, SCREEN_HEIGHT-100+10, 50, 30);
    [SmallBtn setBackgroundImage:[UIImage imageNamed:@"Small.png"] forState:UIControlStateNormal];
    [SmallBtn setTitle:[NSString stringWithFormat:@"%d",a] forState:UIControlStateNormal];
    [SmallBtn setTitleColor:[UIColor orangeColor] forState:UIControlStateNormal];
    [self.view addSubview:SmallBtn];
    
   
    ReductionBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    ReductionBtn.frame = CGRectMake(10, SCREEN_HEIGHT-100+15, 20, 20);
    [ReductionBtn setBackgroundImage:[UIImage imageNamed:@"Reduction.png"] forState:UIControlStateNormal];
    [ReductionBtn addTarget:self action:@selector(PlusAndReduction:) forControlEvents:UIControlEventTouchUpInside];
    ReductionBtn.tag = 200;
    [self.view addSubview:ReductionBtn];
    
    UILabel * otherLab = [[UILabel alloc]initWithFrame:CGRectMake(10+20+10+50+10+20+5, SCREEN_HEIGHT-100, 65, 50)];
    otherLab.text =@"个课时";
    otherLab.adjustsFontSizeToFitWidth = YES;
    otherLab.font = [UIFont systemFontOfSize:17];
    otherLab.textAlignment = NSTextAlignmentLeft;
    [self.view addSubview:otherLab];
    
}
-(void)chooseBoy{
    

    
    RegistrationViewController * reg = [[RegistrationViewController alloc]init];
    reg.number = numberLab.text;
    reg.name = self.name;
    UINavigationController * nav = [[UINavigationController alloc]initWithRootViewController:reg];
    [self  presentViewController:nav animated:YES completion:nil];
    
    
}
-(void)PlusAndReduction:(UIButton *)button{
    
    
    if (a==0) {
        a = 1;
        numberLab.text =[ NSString stringWithFormat:@"%ld元",a*[self.number integerValue]];
        [SmallBtn setTitle:[NSString stringWithFormat:@"%d",a] forState:UIControlStateNormal];

    }else{
        
        
        if (button) {
            
            
            if ( button.tag == 100) {
                
                a+=1;
                
                numberLab.text =[ NSString stringWithFormat:@"%ld元",a*[self.number integerValue]];
                [SmallBtn setTitle:[NSString stringWithFormat:@"%d",a] forState:UIControlStateNormal];
                ////NSLog(@"%d",a);
                
            }else{
                
                if (a == 1) {
                    a=2;
                }
                a-=1;
                
                numberLab.text =[ NSString stringWithFormat:@"%ld元",a*[self.number integerValue]];
                [SmallBtn setTitle:[NSString stringWithFormat:@"%d",a] forState:UIControlStateNormal];
                
                ////NSLog(@"%d",a);
                
                
                
            }
        }
        
    }
    
  
    
        

        
        
    

    
    
    
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
